<!-- 配置管理-设备配置 -->
<template>

  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
           <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属风场">
            <j-select-depart placeholder="请选择所属风场" v-model="queryParam.orgName" @change="change" id="orgName"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="所属项目">
                <j-search-select-tag placeholder="请选择所属项目" v-model="queryParam.productBelong" dict=",," :dictOptions="productBelong" @change="getpb"/>
              </a-form-item>
            </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="物料大类">
              <j-search-select-tag placeholder="请选择物料大类"  v-model="queryParam.codeType" dict=",," :dictOptions="equipTypeCode" @change="getetc"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="物料小类">
                <j-search-select-tag placeholder="请选择物料小类" v-model="queryParam.codeSubType" dict=",," :dictOptions="equipSubtypeCode"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="设备名称">
                <!-- <j-search-select-tag placeholder="请选择设备名称" v-model="queryParam.productName" dict=",," :dictOptions="productName"/> -->
              <a-input placeholder="请选择设备名称" v-model="queryParam.productName"></a-input>
              </a-form-item>
            </a-col>
            </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button
                type="primary"
                @click="searchReset"
                icon="reload"
                style="margin-left: 8px"
              >重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('设备配置')">导出</a-button>
      <a-upload
        name="file"
        :showUploadList="false"
        :multiple="false"
        :headers="tokenHeader"
        :action="importExcelUrl"
        @change="handleImportExcel"
      >
        
      </a-upload>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>删除
          </a-menu-item>
        </a-menu>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt
            style="max-width:80px;font-size: 12px;font-style: italic;"
          >
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)"
          >下载</a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多
              <a-icon type="down"/>
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="open(record)">入库</a>
              </a-menu-item>
              <a-menu-item>
                <a @click="code(record)">二维码</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <dt-c-product-modal ref="modalForm" @ok="modalFormOk"></dt-c-product-modal>
    <!-- <Code ref="modal"></Code> -->
    <a-modal
      title="二维码打印"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
      width="350px"
    >
      <template slot="footer">
        <a-button key="back" @click="handleCancel">返回</a-button>
        <a-button v-print="'#printContent1'" ghost type="primary">打印</a-button>
        <!-- <a-button ghost type="primary" @click="prinfHandle()">打印</a-button> -->
      </template>

      <!--startprint-->
      <div id="printContent1">
        <p id="qrcode1"></p>
        <div id="code1">
          <p>名称：{{this.productNameValue}}</p>
          <p>型号：{{this.productTypeName}}</p>
          <p>项目名称：{{this.productBelongValue}}</p>
        </div>
      </div>
      <!--endprint-->
    </a-modal>

    <a-modal
      title="入库"
      :visible.sync="flag"
      v-if="flag"
      :confirm-loading="confirmLoading"
      @ok="handleOk2"
      @cancel="handleCancel2"
      width="900px"
    >
      <ProductIn :record="record" ref="child"></ProductIn>
    </a-modal>
    
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import DtCProductModal from './modules/DtCProductModal'
import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'
import JSelectDepart from '@/components/jeecgbiz/JSelectDepart'
import JSearchSelectTag from '@/components/dict/JSearchSelectTag'
import Code from '@/components/rqcode/Code'
import { setCookie, getCookie } from '@/utils/cookie'
import QRCode from 'qrcodejs2'
import { setTimeout } from 'timers'
import store from '@/store'
import { httpAction, getAction,postAction } from '@/api/manage'
import ProductIn from '@/components/form/ProductIn'

export default {
  name: 'DtCProductList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDictSelectTag,
    JSelectDepart,
    JSearchSelectTag,
    DtCProductModal,
    Code,
    QRCode,
    ProductIn
  },
  data() {
    return {
      record:{},
      flag:false,
      departIds:'',
      orgname:'',
      visible: false,
      confirmLoading: false,
      text: '123',
      productNameValue: '',
      productTypeName: '',
      productBelongValue: '',
      productEncoding: '',
       equipTypeCode:[],
        equipSubtypeCode:[],
        productName:[],
        productBelong:[],

      code_data: {},
      description: '设备配置管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '部门',
          align: 'center',
          dataIndex: 'orgName_dictText'
        },
        {
          title: '物料大类',
          align: 'center',
          dataIndex: 'codeTypeName'
        },
        {
          title: '物料小类',
          align: 'center',
          dataIndex: 'codeSubtypeName'
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'productNameValue'
        },
        {
          title: '设备厂家',
          align: 'center',
          dataIndex: 'factoryNameValue'
        },
        {
          title: '规格型号',
          align: 'center',
          dataIndex: 'productTypeName'
        },
        {
          title: '所属项目',
          align: 'center',
          dataIndex: 'productBelongValue'
        },
        {
          title: '设备用途',
          align: 'center',
          dataIndex: 'productUsing'
        },

        {
          title: '告警数量',
          align: 'center',
          dataIndex: 'riskSurplus'
        },
        {
          title: '库存数量',
          align: 'center',
          dataIndex: 'surplusNum'
        },
        {
          title: '单价',
          align: 'center',
          dataIndex: 'unitPrice'
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'unitValue'
        },
        {
          title: '是否本厂',
          align: 'center',
          dataIndex: 'ootext'
        },
        {
          title: '存放位置',
          align: 'center',
          dataIndex: 'productArea'
        },
        {
          title: '设备编码',
          align: 'center',
          dataIndex: 'productEncodings'
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark'
        },
        {
          title: '文件',
          align: 'center',
          dataIndex: 'fileName',
          scopedSlots: { customRender: 'fileSlot' }
        },
        {
          title: '物料编码',
          align: 'center',
          dataIndex: 'productEncoding'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/dtproduct/dtCProduct/list',
        delete: '/dtproduct/dtCProduct/delete',
        deleteBatch: '/dtproduct/dtCProduct/deleteBatch',
        exportXlsUrl: '/dtproduct/dtCProduct/exportXls',
        importExcelUrl: 'dtproduct/dtCProduct/importExcel',
        getequipTypeCode1:"/dtproduct/dtCProduct/queryProductByParam",
        add:'/dt_product_put_storage/dtProductPutStorage/addIn',
      
      },
      dictOptions: {}
    }
  },
  created() {},
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    open(record){
      this.flag = true;
      console.log('record',record)
      this.record = record
    },
    handleOk2(e) {
      this.confirmLoading = true
      this.flag = false
      this.confirmLoading = false
      console.log('确定',this.record)
      var params = {
            productId: this.record.id,
            productPutInAmount:this.$refs.child.num,
            remark:this.$refs.child.remark,
            userName:store.getters.userInfo.username
        }
          postAction(this.url.add, params).then(res => {
                    console.log('add',res)
                })
    },
    handleCancel2(e) {
      console.log('Clicked cancel button')
      this.flag = false
    },

    initDictConfig() {},
    code(record) {
      console.log('二维码', record)
      this.productNameValue = record.productNameValue
      this.productEncoding = record.productEncoding
      this.productBelongValue = record.productBelongValue
      this.productTypeName = record.productTypeName
      this.visible = true
      this.qrcode(record)
    },

    handleOk(e) {
      this.confirmLoading = true
      this.visible = false
      this.confirmLoading = false
      
    },
    handleCancel(e) {
      console.log('Clicked cancel button')
      this.visible = false
    },
    prinfHandle() {
            this.$p({
               eg: this.$refs.son,  //打印目标dom节点，eg: this.refs.view
                debug: true,             //打开调试模式，会显示iframe,
                importCss: true,         //引入head 中的link stylesheet
                importStyle: true,       //引入style标签中的样式
                loadCss: [],             //需要载入的第三方样式表
                title: '',               //打印标题
                delay: 300,              //延迟打印时间，确保iframe中的静态资源加载完成
                beforePrinfHandle: null, //打开打印窗口前的钩子函数,可以针对打印文档进行自定义调整，接受一个document参数
                afterPrintHandle: null,  //打印完成的钩子函数,
            });
        },

   
    qrcode(record) {
      setTimeout(function() {
        document.getElementById('qrcode1').innerHTML = ''
        let qrcode = new QRCode('qrcode1', {
          width: 132,
          height: 132,
          text: record.productEncoding, // 二维码地址
          colorDark: '#000',
          colorLight: '#fff'
        })

        var qrcode2 = document.getElementById("qrcode1")
        console.log("内容===",qrcode2.innerHTML)
      }, 100)

      setTimeout(function() {
          var a = document.getElementById("qrcode1")
          console.log("1a--->",a);
          console.log("1a--->", a.childNodes[0]);
          var b = a.childNodes[0];
          a.removeChild(b);
        }, 150)
      
    },
     //选择部门之后再
      change(value){   
        console.log('value',value)
        this.departIds = value
       if(value == ''){
         console.log('没有')
          var obj = {};
          var objlist = [];
          objlist.push(obj);
         this.productBelong = objlist;
         this.equipTypeCode = objlist;
          this.productName = objlist;
          this.productType = objlist;
          this.factoryName = objlist;
       }else{
         this.getproductBelong()
       }
      },
      //所属项目选择
      getpb(value){
       console.log('value111111',value)
       if(value == undefined){
         console.log('没选')
          var obj = {};
          var objlist = [];
          objlist.push(obj);
          this.equipTypeCode = objlist;
          this.productName = objlist;
          this.productType = objlist;
          this.factoryName = objlist;
       }else{
         this.pb = value;
        this.getequipTypeCode()
        this.getproductName()
        this.productType1()
        this.getfactoryName1()
       }
        
      },
      //物料大类选择
      getetc(value){
        if(value == undefined){
          var obj = {};
          var objlist = [];
          objlist.push(obj);
          this.equipSubtypeCode = objlist

        }else{
           this.etc = value
          this.getequipSubtypeCode()
        }
       
      },

       //物料大类
      getequipTypeCode(){
        this.equipTypeCode = []
       var params = {};
        params.codeType = 'code100000';
        params.codeSortId = '100000';
       //params.content1 = '999999999';
        params.content5 = '';
        params.productBelong = this.pb;
        params. orgName= this.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            var objlist = [];
            if (res.success) {
              for(var i=0;i<res.result.length;i++){
                var obj = {};
                obj.value = res.result[i].dtPCode;
                obj.text = res.result[i].dtPValue;
                obj.title = res.result[i].dtPValue;
                objlist.push(obj);
              }
              console.log(objlist)
              this.equipTypeCode = objlist;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })

      },
      //物料小类
      getequipSubtypeCode(){
        this.equipSubtypeCode.length=0;
        var params = {};
        var objlist = [];
        params.codeType = 'code200000';
        params.codeSortId = '200000';
       //params.content1 = '999999999';
        params.content5 = this.etc;
        params.productBelong = this.pb;
        params. orgName= this.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            console.log("res=",res)
            console.log("res.result==<<<<<",res.result)
              if (res.success) {
                  if(res.result.length == 0){
                    this.equipSubtypeCode.length=0;
                    var obj = {};
                      objlist.push(obj);
                      this.equipSubtypeCode = objlist;
                  }else{
                    for(var i=0;i<res.result.length;i++){
                      var obj = {};
                      obj.value = res.result[i].dtPCode;
                      obj.text = res.result[i].dtPValue;
                      obj.title = res.result[i].dtPValue;
                      objlist.push(obj);
                    }
                    console.log(objlist)
                    this.equipSubtypeCode = objlist;
                }
              }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })
          
      },
      //物料名称
      getproductName(){
         this.equipTypeCode = []
       var params = {};
        params.codeType = 'code500000';
        params.codeSortId = '500000';
       //params.content1 = '999999999';
        params.productBelong = this.pb;
        params.orgName= this.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            var objlist = [];
            if (res.success) {
              for(var i=0;i<res.result.length;i++){
                var obj = {};
                obj.value = res.result[i].dtPCode;
                obj.text = res.result[i].dtPValue;
                obj.title = res.result[i].dtPValue;
                objlist.push(obj);
              }
              console.log(objlist)
              this.productName = objlist;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })

      },
      //设备厂家
      getfactoryName1(){
          this.equipTypeCode = []
       var params = {};
        params.codeType = 'code300000';
        params.codeSortId = '300000';
       //params.content1 = '999999999';
        params.productBelong = this.pb;
        params.orgName= this.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            var objlist = [];
            if (res.success) {
              for(var i=0;i<res.result.length;i++){
                var obj = {};
                obj.value = res.result[i].dtPCode;
                obj.text = res.result[i].dtPValue;
                obj.title = res.result[i].dtPValue;
                objlist.push(obj);
              }
              console.log(objlist)
              this.factoryName = objlist;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })

      },
      //规格型号
      productType1(){
         this.equipTypeCode = []
       var params = {};
        params.codeType = 'code400000';
        params.codeSortId = '400000';
       //params.content1 = '999999999';
        params.productBelong = this.pb;
        params.orgName= this.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            var objlist = [];
            if (res.success) {
              for(var i=0;i<res.result.length;i++){
                var obj = {};
                obj.value = res.result[i].dtPCode;
                obj.text = res.result[i].dtPValue;
                obj.title = res.result[i].dtPValue;
                objlist.push(obj);
              }
              console.log(objlist)
              this.productType = objlist;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })

      },
      //所属项目
      getproductBelong(){
        var params = {};
        params.codeType = 'code600000';
        params.codeSortId = '600000';
       //params.content1 = '999999999';
        params.orgName = this.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            var objlist = [];
            if (res.success) {
              for(var i=0;i<res.result.length;i++){
                var obj = {};
                obj.value = res.result[i].dtPCode;
                obj.text = res.result[i].dtPValue;
                obj.title = res.result[i].dtPValue;
                objlist.push(obj);
              }
              console.log(objlist)
              this.productBelong = objlist;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })
      },
      getpb1(){
          var params = {};
        params.codeType = 'code600000';
        params.codeSortId = '600000';
       //params.content1 = '999999999';
        params.orgName = store.getters.userInfo.departIds;
        getAction(this.url.getequipTypeCode1, params).then((res) => {
            var objlist = [];
            if (res.success) {
              for(var i=0;i<res.result.length;i++){
                var obj = {};
                obj.value = res.result[i].dtPCode;
                obj.text = res.result[i].dtPValue;
                obj.title = res.result[i].dtPValue;
                objlist.push(obj);
              }
              console.log(objlist)
              this.productBelong = objlist;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
         })

      }
  },
  mounted() {
       this.getpb1()
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
#printContent1 {
  display: flex;
  text-align: center;
  justify-content: space-around;
}
</style>